Area and Perimeter Calculator
Use this calculator to find the area and perimeter (or circumference for a circle) of common geometric shapes. Select a shape, enter its dimensions, and click "Calculate".
.area-perimeter-calculator-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 8px;
padding: 25px;
max-width: 600px;
margin: 20px auto;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
color: #333;
}
.area-perimeter-calculator-container h2 {
text-align: center;
color: #2c3e50;
margin-bottom: 20px;
font-size: 1.8em;
}
.area-perimeter-calculator-container p {
text-align: center;
margin-bottom: 25px;
line-height: 1.6;
color: #555;
}
.calculator-form .form-group {
margin-bottom: 18px;
display: flex;
align-items: center;
flex-wrap: wrap;
}
.calculator-form label {
flex: 0 0 120px;
margin-right: 15px;
font-weight: bold;
color: #34495e;
font-size: 1.05em;
}
.calculator-form input[type="number"],
.calculator-form select {
flex: 1;
padding: 10px 12px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1em;
box-sizing: border-box;
min-width: 150px;
}
.calculator-form input[type="number"]:focus,
.calculator-form select:focus {
border-color: #007bff;
outline: none;
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}
.calculator-form span {
margin-left: 10px;
font-weight: normal;
color: #666;
}
.calculator-form button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1em;
font-weight: bold;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
margin-top: 20px;
}
.calculator-form button:hover {
background-color: #218838;
transform: translateY(-2px);
}
.calculator-form button:active {
transform: translateY(0);
}
.calculator-result {
margin-top: 30px;
padding: 20px;
background-color: #e9f7ef;
border: 1px solid #d4edda;
border-radius: 8px;
font-size: 1.1em;
color: #155724;
text-align: center;
line-height: 1.8;
font-weight: bold;
}
.calculator-result strong {
color: #0f3d1a;
}
.calculator-result p {
margin: 5px 0;
text-align: center;
}
.shape-inputs {
border-top: 1px solid #eee;
padding-top: 15px;
margin-top: 15px;
}
@media (max-width: 480px) {
.calculator-form label {
flex: 1 0 100%;
margin-bottom: 5px;
}
.calculator-form input[type="number"],
.calculator-form select {
flex: 1 0 100%;
}
.calculator-form span {
margin-left: 0;
margin-top: 5px;
flex: 1 0 100%;
text-align: right;
}
}
function updateInputVisibility() {
var shape = document.getElementById("shapeSelect").value;
document.getElementById("rectangleInputs").style.display = "none";
document.getElementById("squareInputs").style.display = "none";
document.getElementById("circleInputs").style.display = "none";
if (shape === "rectangle") {
document.getElementById("rectangleInputs").style.display = "block";
} else if (shape === "square") {
document.getElementById("squareInputs").style.display = "block";
} else if (shape === "circle") {
document.getElementById("circleInputs").style.display = "block";
}
document.getElementById("resultOutput").innerHTML = ""; // Clear previous results
}
function calculateAreaPerimeter() {
var shape = document.getElementById("shapeSelect").value;
var area = 0;
var perimeter = 0;
var resultHtml = "";
var isValid = true;
if (shape === "rectangle") {
var length = parseFloat(document.getElementById("rectLength").value);
var width = parseFloat(document.getElementById("rectWidth").value);
if (isNaN(length) || length <= 0 || isNaN(width) || width <= 0) {
resultHtml = "Please enter valid positive numbers for Length and Width.";
isValid = false;
} else {
area = length * width;
perimeter = 2 * (length + width);
resultHtml = "
Rectangle Area: " + area.toFixed(2) + " square units" +
"
Rectangle Perimeter: " + perimeter.toFixed(2) + " units";
}
} else if (shape === "square") {
var side = parseFloat(document.getElementById("squareSide").value);
if (isNaN(side) || side <= 0) {
resultHtml = "Please enter a valid positive number for Side Length.";
isValid = false;
} else {
area = side * side;
perimeter = 4 * side;
resultHtml = "
Square Area: " + area.toFixed(2) + " square units" +
"
Square Perimeter: " + perimeter.toFixed(2) + " units";
}
} else if (shape === "circle") {
var radius = parseFloat(document.getElementById("circleRadius").value);
if (isNaN(radius) || radius <= 0) {
resultHtml = "Please enter a valid positive number for Radius.";
isValid = false;
} else {
area = Math.PI * radius * radius;
perimeter = 2 * Math.PI * radius; // Circumference
resultHtml = "
Circle Area: " + area.toFixed(2) + " square units" +
"
Circle Circumference: " + perimeter.toFixed(2) + " units";
}
}
document.getElementById("resultOutput").innerHTML = resultHtml;
}
// Initialize visibility on page load
window.onload = updateInputVisibility;
Understanding Area and Perimeter: A Comprehensive Guide
Area and perimeter are fundamental concepts in geometry that help us quantify the size and boundary of two-dimensional shapes. Whether you're designing a room, planning a garden, or simply trying to understand the world around you, these measurements are incredibly useful.
What is Perimeter?
The perimeter of a two-dimensional shape is the total distance around its boundary. Imagine walking along the edges of a shape; the total distance you cover is its perimeter. It's a one-dimensional measurement, typically expressed in units like meters, feet, inches, or centimeters.
- Rectangle: The perimeter of a rectangle is calculated by adding the lengths of all four sides. Since opposite sides are equal, the formula is
P = 2 × (Length + Width).
- Square: A square is a special type of rectangle where all four sides are equal. So, its perimeter is simply four times the length of one side:
P = 4 × Side.
- Circle (Circumference): For a circle, the perimeter is called the circumference. It's the distance around the circle. The formula involves Pi (π ≈ 3.14159) and the radius (r) or diameter (d):
C = 2 × π × r or C = π × d.
What is Area?
The area of a two-dimensional shape is the amount of surface it covers. It's a measure of the space inside the boundary of the shape. Area is a two-dimensional measurement, expressed in square units like square meters (m²), square feet (ft²), or square centimeters (cm²).
- Rectangle: The area of a rectangle is found by multiplying its length by its width:
A = Length × Width.
- Square: For a square, since length and width are the same (side length), the area is the side length multiplied by itself:
A = Side × Side or A = Side².
- Circle: The area of a circle is calculated using Pi (π) and the square of its radius (r):
A = π × r².
How to Use the Area and Perimeter Calculator
Our calculator simplifies these calculations for you. Here's how to use it:
- Select Shape: Choose the geometric shape you want to analyze from the dropdown menu (Rectangle, Square, or Circle).
- Enter Dimensions: Based on your selection, input the required dimensions.
- For a Rectangle, enter its Length and Width.
- For a Square, enter its Side Length.
- For a Circle, enter its Radius.
Ensure you enter positive numerical values.
- Calculate: Click the "Calculate" button.
- View Results: The calculator will instantly display the area and perimeter (or circumference) of your chosen shape, along with the appropriate units.
Practical Examples
Let's look at some real-world scenarios where this calculator comes in handy:
Example 1: Fencing a Rectangular Garden
You have a rectangular garden that is 15 units long and 8 units wide. You want to put a fence around it and also cover it with mulch.
- Perimeter (Fence): Using the calculator, select "Rectangle", enter Length = 15 and Width = 8. The perimeter will be
2 × (15 + 8) = 46 units. You'll need 46 units of fencing.
- Area (Mulch): The area will be
15 × 8 = 120 square units. You'll need enough mulch to cover 120 square units.
Example 2: Painting a Square Wall
You need to paint a square wall that has a side length of 10 units.
- Area (Paint): Select "Square", enter Side Length = 10. The area will be
10 × 10 = 100 square units. This tells you how much paint you'll need.
- Perimeter (Trim): The perimeter will be
4 × 10 = 40 units. This is useful if you want to add decorative trim around the edges of the wall.
Example 3: Covering a Circular Tabletop
You have a circular tabletop with a radius of 0.5 units and want to buy a custom-fit tablecloth and a decorative edge trim.
- Area (Tablecloth): Select "Circle", enter Radius = 0.5. The area will be
π × (0.5)² ≈ 0.79 square units. This is the size of the tablecloth you need.
- Circumference (Trim): The circumference will be
2 × π × 0.5 ≈ 3.14 units. This is the length of trim required for the edge.
Understanding and calculating area and perimeter are essential skills for various tasks, from home improvement projects to academic studies. Our calculator provides a quick and accurate way to get these measurements, helping you plan and execute your projects with confidence.